package com.sojoys.artifact.factory.template;

import java.io.File;
import java.io.IOException;

import freemarker.ext.beans.BeansWrapper;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;

/**
 * @author : DengYing
 * @CreateDate : 2017年7月6日 上午10:28:31
 * @Description ：Please describe this document
 */
@SuppressWarnings("rawtypes")
public class FreemarkerTemplateFactory implements ITemplateFactory{
	@Override
	public IConfiguration classForTemplateLoading(Class<?> clazz, String rootPath) throws IOException {
		Configuration configuration = new Configuration();
		configuration.setClassForTemplateLoading(clazz, rootPath);
		configuration.setObjectWrapper(new DefaultObjectWrapper());
		return new FreemarkerConfiguration(configuration);
	}

	@Override
	public IConfiguration directoryForTemplateLoading(String rootPath) throws IOException {
		Configuration configuration = new Configuration();
		configuration.setDirectoryForTemplateLoading(new File(rootPath));
		configuration.setObjectWrapper(new BeansWrapper());
		return new FreemarkerConfiguration(configuration);
	}

}
